package com.kgcx.organization.service;

import com.kgcx.common.bean.RequestData;
import com.kgcx.common.constant.Cons;
import com.kgcx.dbutils.utils.CityUtils;
import com.kgcx.dbutils.utils.PageUtils;
import com.kgcx.organization.domain.AirportTerminal;
import com.kgcx.organization.mapper.AirportTerminalMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AirportTerminalService {
    @Autowired
    private AirportTerminalMapper airportTerminalMapper;

    public AirportTerminal getAirportTerminal(Long kid) {
        return airportTerminalMapper.selectByPrimaryKey(kid);
    }

    public List<AirportTerminal> getAirportTerminalList(RequestData rd) {
        rd.put("cityId", CityUtils.getCityId(rd));
        PageUtils.page(rd);
        return airportTerminalMapper.getAirportTerminalList(rd);
    }

    @Transactional(rollbackFor = Exception.class)
    public void addAirportTerminal(AirportTerminal airportTerminal) {
        airportTerminalMapper.insertSelective(airportTerminal);
    }

    @Transactional(rollbackFor = Exception.class)
    public void updateAirportTerminal(AirportTerminal airportTerminal) {
        airportTerminalMapper.updateByPrimaryKeySelective(airportTerminal);
    }

    @Transactional(rollbackFor = Exception.class)
    public void removeAirportTerminal(Long kid) {
        AirportTerminal airportTerminal = new AirportTerminal();
        airportTerminal.setKid(kid);
        airportTerminal.setStatus(Cons.COMMON_STATUS_DELETE);
        airportTerminalMapper.updateByPrimaryKeySelective(airportTerminal);
    }
}
